package com.tencent.smtt.utils;

import com.tencent.smtt.utils.d;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public final class i extends Thread {
    final /* synthetic */ String a;
    final /* synthetic */ d.a b;

    /* JADX INFO: Access modifiers changed from: package-private */
    public i(String str, d.a aVar) {
        this.a = str;
        this.b = aVar;
    }

    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:16:0x0054 -> B:31:0x007a). Please submit an issue!!! */
    @Override // java.lang.Thread, java.lang.Runnable
    public void run() {
        FileOutputStream fileOutputStream;
        InputStream inputStream = null;
        r0 = null;
        FileOutputStream fileOutputStream2 = null;
        inputStream = null;
        try {
            try {
                HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://soft.tbs.imtt.qq.com/17421/tbs_res_imtt_tbs_DebugPlugin_DebugPlugin.tbs").openConnection();
                int contentLength = httpURLConnection.getContentLength();
                httpURLConnection.setConnectTimeout(5000);
                httpURLConnection.connect();
                InputStream inputStream2 = httpURLConnection.getInputStream();
                try {
                    fileOutputStream2 = j.d(new File(this.a));
                    byte[] bArr = new byte[8192];
                    int i = 0;
                    while (true) {
                        int read = inputStream2.read(bArr);
                        if (read <= 0) {
                            break;
                        }
                        i += read;
                        fileOutputStream2.write(bArr, 0, read);
                        this.b.a((i * 100) / contentLength);
                    }
                    this.b.a();
                    try {
                        inputStream2.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    fileOutputStream2.close();
                } catch (Exception e2) {
                    e = e2;
                    fileOutputStream = fileOutputStream2;
                    inputStream = inputStream2;
                    try {
                        e.printStackTrace();
                        this.b.a(e);
                        try {
                            inputStream.close();
                        } catch (Exception e3) {
                            e3.printStackTrace();
                        }
                        fileOutputStream.close();
                    } catch (Throwable th) {
                        th = th;
                        try {
                            inputStream.close();
                        } catch (Exception e4) {
                            e4.printStackTrace();
                        }
                        try {
                            fileOutputStream.close();
                        } catch (Exception e5) {
                            e5.printStackTrace();
                        }
                        throw th;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    fileOutputStream = fileOutputStream2;
                    inputStream = inputStream2;
                    inputStream.close();
                    fileOutputStream.close();
                    throw th;
                }
            } catch (Exception e6) {
                e = e6;
                fileOutputStream = null;
            } catch (Throwable th3) {
                th = th3;
                fileOutputStream = null;
            }
        } catch (Exception e7) {
            e7.printStackTrace();
        }
    }
}
